home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CPath.cp < prev    next >
Text File  |  1994-04-27  |  4KB  |  159 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| This file contains the implementation of the CPath class.  A CPath
  3. //| is a graphics primitive.  It implements a path composed of line segments.
  4. //|________________________________________________________________________________
  5.  
  6.  
  7. #include "CPath.h"
  8. #include "CHyperCuberPrefs.h"
  9. #include <CList.h>
  10.  
  11.  
  12. //============================ External Globals ============================\\
  13.  
  14. extern CHyperCuberPrefs    *gPrefs;
  15.  
  16.  
  17. //============================ Prototypes ============================\\
  18.  
  19. void DrawAntialiasedLine(long x1, long y1, long x2, long y2, RGBColor *color,
  20.                                 Rect *clip_rect);
  21.  
  22.  
  23. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. //| CPath::IPath
  25. //|
  26. //| Purpose: Initialize a path.
  27. //|
  28. //| Parameters: colors:   the color list
  29. //|_________________________________________________________
  30.  
  31. void CPath::IPath(CList *colors)
  32. {
  33.  
  34.     CPrimitive::IPrimitive(colors);                    //  Initialize superclass
  35.  
  36.     path_vertex_indices = new(CList);                //  Initialize the path vertex index list
  37.     path_vertex_indices->IList();
  38.     
  39. }    //==== CPath::IPath() ====\\
  40.  
  41.  
  42.  
  43. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. //| CPath::Dispose
  45. //|
  46. //| Purpose: Dispose of the polygon.
  47. //|
  48. //| Parameters: none
  49. //|_________________________________________________________
  50.  
  51. void CPath::Dispose(void)
  52. {
  53.  
  54.     path_vertex_indices->Dispose();                    //  Get rid of the path vertex index list
  55.  
  56.     CPrimitive::Dispose();                            //  Dispose of superclass
  57.  
  58. }    //==== CPath::Dispose() ====\\
  59.  
  60.  
  61.  
  62. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. //| Operator >> to extract CPath from stream
  64. //|
  65. //| Purpose: Read this path from the input stream
  66. //|
  67. //| Parameters: none
  68. //|_________________________________________________________
  69.  
  70. istream& operator>> (istream& s, CPath& p)
  71. {
  72.  
  73.     s >> p.color_index;                                            //  Get index of this point's color
  74.  
  75.     short num_vertices;                                            //  Get number of vertices
  76.     s >> num_vertices;    
  77.  
  78.     short i;
  79.     for (i = 1; i <= num_vertices; i++)
  80.         {
  81.         long vertex_index;                                        //  Get index of the vertex
  82.         s >> vertex_index;    
  83.         
  84.         p.path_vertex_indices->Append((CObject *)vertex_index);    //  Add the vertex to the path
  85.         }
  86.     
  87.     return s;
  88.     
  89. }    //==== Operator >> to extract CPath from stream ====\\
  90.  
  91.  
  92.  
  93. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94. //| CPath::Draw
  95. //|
  96. //| Purpose: Draw this path.
  97. //|
  98. //| Parameters: override_color:  the color to use to draw the primitive
  99. //|                              If this is NULL, use the primitive's default
  100. //|             screen_vertices: the screen coordinates of the vertices
  101. //|             clip_rect:       the clipping rectangle
  102. //|             fAntialias:      TRUE if we should antialias
  103. //|__________________________________________________________________________
  104.  
  105. void CPath::Draw(RGBColor *override_color, Point **screen_vertices,
  106.                     Rect *clip_rect, Boolean fAntialias)
  107. {
  108.     
  109.     short num_vertices = path_vertex_indices->GetNumItems();        //  Get number of points
  110.  
  111.     RGBColor *draw_color = (override_color) ?
  112.                             override_color :
  113.                             *((RGBColor **) colors->NthItem(color_index));
  114.  
  115.     long vertex_index = (long) path_vertex_indices->NthItem(1)-1;    //  Get index of the first point
  116.  
  117.     Point screen_point = *(*screen_vertices + vertex_index);    //  Get the screen point
  118.         
  119.     short i;
  120.     if (fAntialias)        //  Antialias line segments
  121.         {
  122.         
  123.         Point last_screen_point = screen_point;
  124.         
  125.         for (i = 2; i <= num_vertices; i++)
  126.             {
  127.             
  128.             vertex_index = (long) path_vertex_indices->NthItem(i)-1;    //  Get index of this point
  129.             screen_point = *(*screen_vertices + vertex_index);            //  Get this screen point
  130.  
  131.             DrawAntialiasedLine(screen_point.h, screen_point.v,
  132.                                 last_screen_point.h, last_screen_point.v,
  133.                                 draw_color,
  134.                                 clip_rect);
  135.             
  136.             last_screen_point = screen_point;                        //  Remember this point
  137.  
  138.             }
  139.         }
  140.     
  141.     else                                //  Don't antialias line segments
  142.         {
  143.         RGBForeColor(draw_color);                                    //  Use specified color, if any
  144.     
  145.         MoveTo(screen_point.h, screen_point.v);                        //  Start here
  146.     
  147.         for (i = 2; i <= num_vertices; i++)
  148.             {
  149.             
  150.             vertex_index = (long) path_vertex_indices->NthItem(i)-1;//  Get index of this point
  151.             screen_point = *(*screen_vertices + vertex_index);        //  Get this screen point
  152.     
  153.             LineTo(screen_point.h, screen_point.v);                    //  Draw the line segment
  154.     
  155.             }
  156.         }
  157.  
  158. }    //==== CPath::Draw() ====\\
  159.